﻿@using OpenForum.Core.Views;

@model OpenForum.Core.ViewModels.Interfaces.IViewViewModel

<div class="openforum_container">
    
    @(Model.IncludeDefaultStyles ? Html.Raw(ForumViewHelper.GetDefaultStyles()) : MvcHtmlString.Empty)
    @(Model.IncludeValidationSummary ? Html.ValidationSummary() : MvcHtmlString.Empty)
    
    <div class="openforum_title">@Model.Post.Title</div>

    <table class="openforum_maincontent">
        <tr>
            <td class="openforum_body">@Html.Raw(Model.Post.Body)</td>

            @if (Model.Post.CreatedBy.HasImageUrl)
            {
            <td class="openforum_user_image">
                <div><img src="@Model.Post.CreatedBy.ImageUrl" alt="@Model.Post.CreatedBy.Username" /></div>
            </td>
            }

            <td class="openforum_user">
                <div>                
                    @if (Model.Post.CreatedBy.HasUserUrl) 
                    {
                        <a href="@Model.Post.CreatedBy.UserUrl">@Model.Post.CreatedBy.Username</a>
                    } 
                    else 
                    {
                        @Model.Post.CreatedBy.Username
                    }
                </div>
                
                <div>@Model.Post.CreatedDate.ToString("MM/dd/yyyy HH:mm tt")</div>

                @(Model.CurrentUser != null && Model.Post.CreatedById == Model.CurrentUser.Id ? Html.ActionLink("Edit", "Post", new { id = Model.Post.Id }) : MvcHtmlString.Empty)

            </td>
        </tr>

        @foreach (var item in Model.Post.Replies)
        {
            
        <tr>
            <td class="openforum_body">@Html.Raw(item.Body)</td>

            @if (item.CreatedBy.HasImageUrl) 
            { 
            <td class="openforum_user_image">
                <div><img src="@item.CreatedBy.ImageUrl" alt="@item.CreatedBy.Username" /></div>
            </td>
            }

            <td class="openforum_user">
                <div>
                
                    @if (item.CreatedBy.HasUserUrl)
                    { 
                        <a href="@item.CreatedBy.UserUrl %>">@item.CreatedBy.Username</a>
                    }
                    else
                    {
                        @item.CreatedBy.Username
                    }
                
                </div>
                
                <div>@item.CreatedDate.ToString("MM/dd/yyyy HH:mm tt")</div>

                @(Model.CurrentUser != null && item.CreatedById == Model.CurrentUser.Id ? Html.ActionLink("Edit", "Reply", new { id = item.Id, postId = Model.Post.Id }) : MvcHtmlString.Empty)

            </td>
        </tr>
            
        }

    </table>

    <div class="openforum_actions">
        @Html.ActionLink("Back", "index")
        @Html.ActionLink("Reply", "Reply", new { id = "", postId = Model.Post.Id, title = ForumViewHelper.ToUrlFriendlyTitle(Model.Post.Title) })
    </div>
</div>
